import request from "@/utils/request";
import { AxiosPromise } from "axios";
import {
  DictTypeQuery,
  DictTypePageResult,
  DictTypeForm,
  DictQuery,
  DictPageResult,
} from "./types";

/**
 * 登录成功后获取所有字典集合
 */
export function getDictInfo(): AxiosPromise<OptionType[]> {
  return request({
    url: "/system/dictionary/getAllDictionaryItems",
    method: "post",
    data: {},
  });
}

/**
 * 获取字典类型的数据项
 *
 * @param typeCode 字典类型编码
 */
export function getDictOptions(data: object): AxiosPromise<OptionType[]> {
  return request({
    url: "/system/dictionary/getDictionarys",
    method: "post",
    data: data,
  });
}

/**
 * 字典类型分页列表
 *
 * @param queryParams
 */
export function getDictTypePage(
  queryParams: DictTypeQuery
): AxiosPromise<DictTypePageResult> {
  return request({
    url: "/system/dictionary/queryPage",
    method: "post",
    data: queryParams,
  });
}

/**
 * 字典类型表单数据
 *
 * @param id
 */
export function getDictTypeForm(data: any): AxiosPromise<DictTypeForm> {
  return request({
    url: "/system/dictionary/get/" + data.id,
    method: "post",
    data: {},
  });
}

/**
 * 新增字典类型
 *
 * @param data
 */
export function addDictType(data: any) {
  return request({
    url: "/system/dictionary/save",
    method: "post",
    data: data,
  });
}

/**
 * 删除字典类型
 */
export function deleteDictTypes(data: any) {
  return request({
    url: "/system/dictionary/deleteList",
    method: "post",
    data: data,
  });
}

/**
 * 删除字典
 *
 * @param ids 字典项ID，多个以英文逗号(,)分割
 */
export function deleteDict(data: any) {
  return request({
    url: "/system/dictionary/deleteItemList",
    method: "post",
    data: data,
  });
}

/**
 * 字典分页列表
 */
export function getDictPage(
  queryParams: DictQuery
): AxiosPromise<DictPageResult> {
  return request({
    url: "/system/dictionary/queryItemPage",
    method: "post",
    data: queryParams,
  });
}

/**
 * 新增字典
 *
 * @param data
 */
export function addDict(data: any) {
  return request({
    url: "/system/dictionary/saveItem",
    method: "post",
    data: data,
  });
}
